package com.guqj.pattern.proxy;

public class ProxyVisitor implements Visitor {

	private Visitor visitor;

	public ProxyVisitor() {
		this(new Tourist());
	}

	public ProxyVisitor(Visitor visitor) {
		this.visitor = visitor;
	}

	@Override
	public void visit() throws Exception {
		visitor.visit();
	}

	@Override
	public void publish() throws Exception {
		if (visitor instanceof Tourist) {
			throw new Exception("游客禁止发表主题");
		}
		visitor.publish();
	}

	@Override
	public void comment() throws Exception {
		if (visitor instanceof Tourist) {
			throw new Exception("游客禁止评论主题");
		}
		visitor.comment();
	}

	@Override
	public void remove() throws Exception {
		if (visitor instanceof Tourist) {
			throw new Exception("游客禁止删除主题");
		}
		visitor.remove();
	}

}
